{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "667d1e6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "1*2=2\t2*2=4\t\n",
      "1*3=3\t2*3=6\t3*3=9\t\n",
      "1*4=4\t2*4=8\t3*4=12\t4*4=16\t\n",
      "1*5=5\t2*5=10\t3*5=15\t4*5=20\t5*5=25\t\n",
      "1*6=6\t2*6=12\t3*6=18\t4*6=24\t5*6=30\t6*6=36\t\n",
      "1*7=7\t2*7=14\t3*7=21\t4*7=28\t5*7=35\t6*7=42\t7*7=49\t\n",
      "1*8=8\t2*8=16\t3*8=24\t4*8=32\t5*8=40\t6*8=48\t7*8=56\t8*8=64\t\n",
      "1*9=9\t2*9=18\t3*9=27\t4*9=36\t5*9=45\t6*9=54\t7*9=63\t8*9=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "# 打印九九乘法表\n",
    "# 思路：\n",
    "# 1.两个for循环，分别作为乘法表两个数\n",
    "# 2.一排打印，使用一个空字符串拼接打印，且应在循环创建空字符串时\n",
    "# 3去掉重复的,也就是就j>i的去掉\n",
    "for i in range(1,10):\n",
    "    line =  ''  #不可在循环外创建，会将之前的计算好的结果重复打印\n",
    "    for j in range(1,i+1):\n",
    "        spin = f'{j}*{i}={i*j}\\t'\n",
    "        line += spin\n",
    "    print(line)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "9ddcc98a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Plz input your usersname: 46\n",
      "Plz input your password: 54\n",
      "Invalid username or password\n",
      "Plz input your usersname: 5456\n",
      "Plz input your password: 5456\n",
      "Invalid username or password\n",
      "Plz input your usersname: 545\n",
      "Plz input your password: 4545\n",
      "Invalid username or password\n",
      "Login faild\n"
     ]
    }
   ],
   "source": [
    "# 2用户登录验证\n",
    "# 。用户依次输入用户名和密码，然后提交验证\n",
    "# 。用户不存在、密码错误，都显示用户名或密码错误提示。错误3次，则退出程序\n",
    "# 。验证成功则显示登录信息\n",
    "# 思路：1.while循环计数\n",
    "i = 0\n",
    "name =  'adaim'\n",
    "pword = '123123'\n",
    "while 1:\n",
    "    usersname = input('Plz input your usersname: ')\n",
    "    password = input('Plz input your password: ')\n",
    "    i += 1\n",
    "    if usersname == name and password == pword:\n",
    "        print('Login successfully')\n",
    "        break\n",
    "    else:\n",
    "        print('Invalid username or password') \n",
    "        if i == 3:\n",
    "            print('Login faild')\n",
    "            break "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c704de37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   *   \n",
      "  ***  \n",
      " ***** \n",
      "*******\n",
      " ***** \n",
      "  ***  \n",
      "   *   \n"
     ]
    }
   ],
   "source": [
    "# 打印下图菱形\n",
    "# 思路：\n",
    "# 1.使用负索引，方便做出对称效果\n",
    "n = 7\n",
    "for i in range (-3,4):\n",
    "    if i < 0:\n",
    "        i = -i\n",
    "    print(' '*i + '*'*(n-(2*i)) + ' '*i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "0f267089",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "1\n",
      "2\n",
      "3\n",
      "5\n",
      "8\n",
      "13\n",
      "21\n",
      "34\n",
      "55\n",
      "89\n"
     ]
    }
   ],
   "source": [
    "# 打印100以内的斐波那契数列\n",
    "# 思路：\n",
    "# 1.斐波那契数列的特点：1 1 2 3 5 8 13 21 34 55 89 144\n",
    "# 即第三位数开始是前两位数之和\n",
    "a = 0\n",
    "b = 1\n",
    "print(b)\n",
    "    \n",
    "while 1:\n",
    "    c = a + b\n",
    "    if c > 100: break\n",
    "    a = b\n",
    "    b = c\n",
    "    print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "672520f8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index=1,fib=1\n",
      "index=2,fib=1\n",
      "index=3,fib=2\n",
      "index=4,fib=3\n",
      "index=5,fib=5\n",
      "index=6,fib=8\n",
      "index=7,fib=13\n",
      "index=8,fib=21\n",
      "index=9,fib=34\n",
      "index=10,fib=55\n",
      "index=11,fib=89\n",
      "index=12,fib=144\n",
      "index=13,fib=233\n",
      "index=14,fib=377\n",
      "index=15,fib=610\n",
      "index=16,fib=987\n",
      "index=17,fib=1597\n",
      "index=18,fib=2584\n",
      "index=19,fib=4181\n",
      "index=20,fib=6765\n",
      "index=21,fib=10946\n",
      "index=22,fib=17711\n",
      "index=23,fib=28657\n",
      "index=24,fib=46368\n",
      "index=25,fib=75025\n",
      "index=26,fib=121393\n",
      "index=27,fib=196418\n",
      "index=28,fib=317811\n",
      "index=29,fib=514229\n",
      "index=30,fib=832040\n",
      "index=31,fib=1346269\n",
      "index=32,fib=2178309\n",
      "index=33,fib=3524578\n",
      "index=34,fib=5702887\n",
      "index=35,fib=9227465\n",
      "index=36,fib=14930352\n",
      "index=37,fib=24157817\n",
      "index=38,fib=39088169\n",
      "index=39,fib=63245986\n",
      "index=40,fib=102334155\n",
      "index=41,fib=165580141\n",
      "index=42,fib=267914296\n",
      "index=43,fib=433494437\n",
      "index=44,fib=701408733\n",
      "index=45,fib=1134903170\n",
      "index=46,fib=1836311903\n",
      "index=47,fib=2971215073\n",
      "index=48,fib=4807526976\n",
      "index=49,fib=7778742049\n",
      "index=50,fib=12586269025\n",
      "index=51,fib=20365011074\n",
      "index=52,fib=32951280099\n",
      "index=53,fib=53316291173\n",
      "index=54,fib=86267571272\n",
      "index=55,fib=139583862445\n",
      "index=56,fib=225851433717\n",
      "index=57,fib=365435296162\n",
      "index=58,fib=591286729879\n",
      "index=59,fib=956722026041\n",
      "index=60,fib=1548008755920\n",
      "index=61,fib=2504730781961\n",
      "index=62,fib=4052739537881\n",
      "index=63,fib=6557470319842\n",
      "index=64,fib=10610209857723\n",
      "index=65,fib=17167680177565\n",
      "index=66,fib=27777890035288\n",
      "index=67,fib=44945570212853\n",
      "index=68,fib=72723460248141\n",
      "index=69,fib=117669030460994\n",
      "index=70,fib=190392490709135\n",
      "index=71,fib=308061521170129\n",
      "index=72,fib=498454011879264\n",
      "index=73,fib=806515533049393\n",
      "index=74,fib=1304969544928657\n",
      "index=75,fib=2111485077978050\n",
      "index=76,fib=3416454622906707\n",
      "index=77,fib=5527939700884757\n",
      "index=78,fib=8944394323791464\n",
      "index=79,fib=14472334024676221\n",
      "index=80,fib=23416728348467685\n",
      "index=81,fib=37889062373143906\n",
      "index=82,fib=61305790721611591\n",
      "index=83,fib=99194853094755497\n",
      "index=84,fib=160500643816367088\n",
      "index=85,fib=259695496911122585\n",
      "index=86,fib=420196140727489673\n",
      "index=87,fib=679891637638612258\n",
      "index=88,fib=1100087778366101931\n",
      "index=89,fib=1779979416004714189\n",
      "index=90,fib=2880067194370816120\n",
      "index=91,fib=4660046610375530309\n",
      "index=92,fib=7540113804746346429\n",
      "index=93,fib=12200160415121876738\n",
      "index=94,fib=19740274219868223167\n",
      "index=95,fib=31940434634990099905\n",
      "index=96,fib=51680708854858323072\n",
      "index=97,fib=83621143489848422977\n",
      "index=98,fib=135301852344706746049\n",
      "index=99,fib=218922995834555169026\n",
      "index=100,fib=354224848179261915075\n",
      "index=101,fib=573147844013817084101\n"
     ]
    }
   ],
   "source": [
    "# 求斐波那契数列第101项\n",
    "# 思路：\n",
    "# 1.斐波那契数列的特点：1 1 2 3 5 8 13 21 34 55 89 144\n",
    "# 即第三位数开始是前两位数之和\n",
    "a = 0\n",
    "b = 1\n",
    "index = 1\n",
    "print('index={},fib={}'.format(index,b))\n",
    "while 1:\n",
    "    c = a + b\n",
    "    index += 1\n",
    "    print('index={},fib={}'.format(index,c))\n",
    "    if index == 101: break\n",
    "    a = b\n",
    "    b = c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "7fac5085",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "5\n",
      "7\n",
      "11\n",
      "13\n",
      "17\n",
      "19\n",
      "23\n",
      "29\n",
      "31\n",
      "37\n",
      "41\n",
      "43\n",
      "47\n",
      "53\n",
      "59\n",
      "61\n",
      "67\n",
      "71\n",
      "73\n",
      "79\n",
      "83\n",
      "89\n",
      "97\n",
      "101\n",
      "103\n",
      "107\n",
      "109\n",
      "113\n",
      "127\n",
      "131\n",
      "137\n",
      "139\n",
      "149\n",
      "151\n",
      "157\n",
      "163\n",
      "167\n",
      "173\n",
      "179\n",
      "181\n",
      "191\n",
      "193\n",
      "197\n",
      "199\n",
      "211\n",
      "223\n",
      "227\n",
      "229\n",
      "233\n",
      "239\n",
      "241\n",
      "251\n",
      "257\n",
      "263\n",
      "269\n",
      "271\n",
      "277\n",
      "281\n",
      "283\n",
      "293\n",
      "307\n",
      "311\n",
      "313\n",
      "317\n",
      "331\n",
      "337\n",
      "347\n",
      "349\n",
      "353\n",
      "359\n",
      "367\n",
      "373\n",
      "379\n",
      "383\n",
      "389\n",
      "397\n",
      "401\n",
      "409\n",
      "419\n",
      "421\n",
      "431\n",
      "433\n",
      "439\n",
      "443\n",
      "449\n",
      "457\n",
      "461\n",
      "463\n",
      "467\n",
      "479\n",
      "487\n",
      "491\n",
      "499\n",
      "503\n",
      "509\n",
      "521\n",
      "523\n",
      "541\n",
      "547\n",
      "557\n",
      "563\n",
      "569\n",
      "571\n",
      "577\n",
      "587\n",
      "593\n",
      "599\n",
      "601\n",
      "607\n",
      "613\n",
      "617\n",
      "619\n",
      "631\n",
      "641\n",
      "643\n",
      "647\n",
      "653\n",
      "659\n",
      "661\n",
      "673\n",
      "677\n",
      "683\n",
      "691\n",
      "701\n",
      "709\n",
      "719\n",
      "727\n",
      "733\n",
      "739\n",
      "743\n",
      "751\n",
      "757\n",
      "761\n",
      "769\n",
      "773\n",
      "787\n",
      "797\n",
      "809\n",
      "811\n",
      "821\n",
      "823\n",
      "827\n",
      "829\n",
      "839\n",
      "853\n",
      "857\n",
      "859\n",
      "863\n",
      "877\n",
      "881\n",
      "883\n",
      "887\n",
      "907\n",
      "911\n",
      "919\n",
      "929\n",
      "937\n",
      "941\n",
      "947\n",
      "953\n",
      "967\n",
      "971\n",
      "977\n",
      "983\n",
      "991\n",
      "997\n"
     ]
    }
   ],
   "source": [
    "# 求10万内的所有素数\n",
    "# 思路：\n",
    "# 两个for循环让一个书除除本身以外的所有比它和1小得数所有数\n",
    "# 1.除2以外所有的偶数都不是素数\n",
    "# 2.所有能被5整除的都不是素数\n",
    "# 3.任何一个合数都可以分解为几个素数的积\n",
    "n = 1000\n",
    "for i in range(3, n, 2):\n",
    "    if i > 10 and i % 5 == 0:continue\n",
    "    for j in range(3, int(i**0.5)+1, 2):\n",
    "        if i % j == 0:break\n",
    "    else:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a88f3e6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c19686a8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7690d9a0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f68ea4b2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80e416a9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13826f84",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bb17bc0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a77016fa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38973f7f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d60cd49",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62c5fc33",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e83c4ba",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e627f5d2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02d37edc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "653cab4b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2c384fe",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
